package com.atsmart.app.activity;

import android.app.Dialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TextView;

import com.atsmart.app.R;
import com.atsmart.app.utils.DialogUtil;

public class ReportForAllActivity extends TabActivity implements OnClickListener {
	public static final String REPORT_TYPE = "report_type";
	private static Dialog dialog;
	public static ReportForAllActivity instance;
	private Button btnRefresh;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		instance = this;
		setContentView(R.layout.tabs_layout);
		btnRefresh = (Button) findViewById(R.id.btn_refresh);
		btnRefresh.setOnClickListener(this);
		TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
		tabHost.addTab(tabHost.newTabSpec("汇报列表").setIndicator(createTabView(this, "汇报列表")).setContent(new Intent(this, ReportListActivity.class).putExtra(REPORT_TYPE, ReportListActivity.REPORT_TYPE_UNREPORT)));
		tabHost.addTab(tabHost.newTabSpec("已汇报").setIndicator(createTabView(this, "已汇报")).setContent(new Intent(this,ReportListActivity.class).putExtra(REPORT_TYPE, ReportListActivity.REPORT_TYPE_REPORTED)));
		this.setDefaultTab(0);
	}

	private static View createTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_refresh:
			delegate.refresh();
			break;
		default:
			break;
		}
	}

	public static Dialog showLoading() {
		if (dialog == null) {
			dialog = DialogUtil.getLoadingDialog(instance);
			dialog.show();
		}
		return dialog;
	}

	protected static void hideLoading() {
		if (dialog != null) {
			dialog.dismiss();
			dialog = null;
		}
	}

	public static interface Delegate{
		void refresh();
	}

	protected Delegate delegate;

	public Delegate getDelegate(){
		return delegate;
	}

	public void setDelegate(Delegate delegate){
		this.delegate = delegate;
	}

}